//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.sample.library;

import android.annotation.SuppressLint;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.os.IBinder;
import android.os.IInterface;
import android.os.Looper;
import android.os.Parcel;
import android.os.RemoteException;

import java.io.IOException;
import java.util.concurrent.LinkedBlockingQueue;

public class IDFA {
    public IDFA() {
    }

    public static String a(Context var0) {
        try {
            aa var1 = c(var0);
            if (var1 == null) {
                return null;
            }

            if (!var1.a()) {
                return var1.b();
            }
        } catch (Exception var2) {
        }

        return null;
    }

    public static String b(Context var0) {
        try {
            aa var1 = c(var0);
            return var1 == null ? null : var1.b();
        } catch (Exception var2) {
            return null;
        }
    }

    @SuppressLint("WrongConstant")
    private static aa c(Context var0) throws Exception {
        if (Looper.myLooper() == Looper.getMainLooper()) {
            return null;
        } else {
            try {
                PackageManager var1 = var0.getPackageManager();
                var1.getPackageInfo("com.android.vending", 0);
            } catch (Exception var12) {
                throw var12;
            }

            b var15 = new b();
            Intent var2 = new Intent("com.google.android.gms.ads.identifier.service.START");
            var2.setPackage("com.google.android.gms");
            if (!var0.bindService(var2, var15, 1)) {
                throw new IOException("Google Play connection failed");
            } else {
                aa var7;
                try {
                    c var3 = new c(var15.a());
                    boolean var4 = var3.a(true);
                    String var5 = "";
                    if (!var4) {
                        var5 = var3.a();
                    }

                    aa var6 = new aa(var5, var4);
                    var7 = var6;
                } catch (Exception var13) {
                    throw var13;
                } finally {
                    var0.unbindService(var15);
                }

                return var7;
            }
        }
    }

    private static final class c implements IInterface {
        private IBinder a;

        public c(IBinder var1) {
            this.a = var1;
        }

        public IBinder asBinder() {
            return this.a;
        }

        public String a() throws RemoteException {
            Parcel var1 = Parcel.obtain();
            Parcel var2 = Parcel.obtain();

            String var3;
            try {
                var1.writeInterfaceToken("com.google.android.gms.ads.identifier.internal.IAdvertisingIdService");
                this.a.transact(1, var1, var2, 0);
                var2.readException();
                var3 = var2.readString();
            } finally {
                var2.recycle();
                var1.recycle();
            }

            return var3;
        }

        public boolean a(boolean var1) throws RemoteException {
            Parcel var2 = Parcel.obtain();
            Parcel var3 = Parcel.obtain();

            boolean var4;
            try {
                var2.writeInterfaceToken("com.google.android.gms.ads.identifier.internal.IAdvertisingIdService");
                var2.writeInt(var1 ? 1 : 0);
                this.a.transact(2, var2, var3, 0);
                var3.readException();
                var4 = 0 != var3.readInt();
            } finally {
                var3.recycle();
                var2.recycle();
            }

            return var4;
        }
    }

    private static final class b implements ServiceConnection {
        boolean a;
        private final LinkedBlockingQueue<IBinder> b;

        private b() {
            this.a = false;
            this.b = new LinkedBlockingQueue(1);
        }

        public void onServiceConnected(ComponentName var1, IBinder var2) {
            try {
                this.b.put(var2);
            } catch (InterruptedException var4) {
            }

        }

        public void onServiceDisconnected(ComponentName var1) {
        }

        public IBinder a() throws InterruptedException {
            if (this.a) {
                throw new IllegalStateException();
            } else {
                this.a = true;
                return (IBinder) this.b.take();
            }
        }
    }

    private static final class aa {
        private final String a;
        private final boolean b;

        aa(String var1, boolean var2) {
            this.a = var1;
            this.b = var2;
        }

        private String b() {
            return this.a;
        }

        public boolean a() {
            return this.b;
        }
    }
}
